From 79bc1a724654be88f99fb4cc150ed58bab2fc8fd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 17 Nov 2014 10:34:27 -0800 Subject: [PATCH] Be sure to include OUT_DIR for doc tests --- src/cargo/ops/cargo_rustc/mod.rs | 2 ++ tests/test_cargo_compile_custom_build.rs | 34 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 2032f6ec5..21dbcd828 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -148,6 +148,8 @@ pub fn compile_targets<'a>(env: &str, targets: &[&'a Target], pkg: &'a Package, // Now that we've figured out everything that we're going to do, do it! try!(queue.execute(cx.config)); + let out_dir = cx.layout(pkg, KindTarget).build_out(pkg).display().to_string(); + cx.compilation.extra_env.insert("OUT_DIR".to_string(), Some(out_dir)); Ok(cx.compilation) } diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index f373c7440..735bbb84b 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -939,3 +939,37 @@ test!(transitive_dep_host { assert_that(p.cargo_process("build"), execs().with_status(0)); }) + +test!(test_a_lib_with_a_build_command { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + build = "build.rs" + "#) + .file("src/lib.rs", r#" + include!(concat!(env!("OUT_DIR"), "/foo.rs")) + + /// ``` + /// foo::bar(); + /// ``` + pub fn bar() { + assert_eq!(foo(), 1); + } + "#) + .file("build.rs", r#" + use std::os; + use std::io::File; + + fn main() { + let out = Path::new(os::getenv("OUT_DIR").unwrap()); + File::create(&out.join("foo.rs")).write_str(" + fn foo() -> int { 1 } + ").unwrap(); + } + "#); + assert_that(p.cargo_process("test"), + execs().with_status(0)); +}) -- 2.30.2